#! /usr/bin/python
# -*- coding: cp1250 -*-

import glob, re, string, sys, os
import pepe.p_txt.bigtxt as bt

def cleanup_cz(req):
    """ """
    if req <> '':
        a, b = string.split(req, '/')
    else:
        return ''

    a = re.sub('(\s|[a-zA-Z]|^0{1,})', '', a)
    b = re.sub('(\s|[a-zA-Z]|^0{1,})', '', b)

    # a1 (predcislie) is not mandatory, threfore we remove it by "^\d{1,}-
    # example ... 43-27620-65092/7 ... remove just '43'
    a = re.sub('^\d{1,}\-', '', a)
    b = re.sub('^\d{1,}\-', '', b)
    # then remove second -
    a = re.sub('-', '', a)
    b = re.sub('-', '', b)

    if len(a) > len(b):
        a = string.zfill(a, 10)[-10:]
        b = string.zfill(b, 4)
        res = "%s/%s" % (a, b)
    else:
        b = string.zfill(b, 10)[-10:]
        a = string.zfill(a, 4)
        res = "%s/%s" % (b, a)
        
    return res

def cleanup_hu(req):
    """ """
    res = re.sub('(\s|-|\D)', '', req)
    if len(res) > 16:
        res = "%s-%s-%s" % (res[:8], res[8:16], res[16:])
    else:
        res = ''
    return res

def cleanup_pl(req):
    """ """
    res = re.sub('\D', '', req)
    # Account number only. According to http://www.cnb.cz/m2export/sites/www.cnb.cz/cs/platebni_styk/iban/download/TR201.pdf
    res = "%s %s %s %s" % (res[-16:-12], res[-12:-8], res[-8:-4], res[-4:])
    return res

def cleanup_sk(req):
    """ """
    return cleanup_cz(req)

def cleanup_iban(req):
    """ """
    return string.upper(re.sub('(-| )', '', req))

if __name__== '__main__':
    """ """
    pass
